package com.atguigu.lease.web.admin.schedule;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduledTasks {
//要用到哪张表就引用哪个依赖
    @Autowired
    private LeaseAgreementService leaseAgreementService;


//定时检查租约的状态 到期后改为已到期
    @Scheduled(cron = "0 0 */8 * * *")
    public void checkLeaseStatus(){
        //1.租约表里的状态修改为已到期，条件：lease_end_date 在租约结束日期 小于 当前日期new Date()  lt:小于
        leaseAgreementService.update(new LambdaUpdateWrapper<LeaseAgreement>().
                            //      结束日期          当前日期
                lt(LeaseAgreement::getLeaseEndDate,new Date()).
                // 2.租约状态是（2，5）
                in(LeaseAgreement::getStatus,2,5).
                //修改状态为已到期
                set(LeaseAgreement::getStatus, LeaseStatus.EXPIRED));




























    }
}
